home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 529 < prev    next >
Internet Message Format  |  1996-08-06  |  3KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Bit-field sizes
  5. Date: 06 Mar 1996 15:45:02 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar6084502@qcd.lanl.gov>
  8. References: <nzRPxQ9ytZZA084yn@csn.net>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: thads@csn.net's message of 5 Mar 1996 23:49:35 -0700
  13.  
  14. In article <nzRPxQ9ytZZA084yn@csn.net>
  15. thads@csn.net (Thad Smith) writes:
  16.  
  17. TS: Can the size of a bit-field, measured in bits, exceed the size of an
  18. TS: int?  The description of bit-fields describes it as an integral
  19. TS: type with a (programmer-)specified number of bits, not specifically
  20. TS: constrained in size.  ANSI Classic section 3.2.1.1 says, however, that
  21. TS: bit-fields are promoted to either int or unsigned int.  This would
  22. TS: seem to prohibit promoting a large bit-field to a long.  If so, why
  23. TS: was this constraint imposed?
  24.  
  25. 6.5.2.1 constraints: The expression that specifies the width of a
  26. bit-field ... shall not exceed the number of bits in an ordinary
  27. object of compatible type.
  28.  
  29. So, the number of bits cannot exceed the number of bits in an int or
  30. unsigned int.
  31.  
  32. TS: 
  33. TS: Secondly, is the storage unit within which bit-fields are allocated
  34. TS: constrained to be a single size or can it vary, depending on the size
  35. TS: of the bit fields?  I see nothing in the standard prohibiting
  36. TS: different size storage units for bit-fields.  Also bit-fields are
  37.  
  38. Neither do I.
  39.  
  40. TS: explicitly allowed to span multiple storage units, at least if the
  41. TS: bit-field is not the first in a structure (the use of the word "may"
  42. TS: makes the requirement for the first bit-field ambiguous with regard to
  43. TS: storage in a single unit).
  44.  
  45. Depends on whether an addressable storage unit has to occur in
  46. multiples of bytes. (The standard says that bytes are addressable
  47. storage units, but not the converse. If addressable means that & can
  48. be applied to it, again, the smallest addressable unit is a byte). If
  49. it has to, then a width 4 bit field followed by width 2 bit field must
  50. both belong to the same addressable storage unit, and neither can span
  51. storage units.
  52.  
  53. TS: 
  54. TS: If different size storage units are allowed or any bit-field is
  55. TS: allowed to span multiple units, the size of a struct containing
  56. TS: bit-fields might be 1 byte, while bit-fields could be allocated up to
  57. TS: the size (in bits) of ints, possibly four bytes in a particular
  58. TS: implementation, by choosing larger storage units for larger
  59. TS: bit-fields.
  60.  
  61. I guess so.
  62.  
  63. TS: 
  64. TS: Is anyone aware of an implementation using bit-field storage units
  65. TS: smaller than int?
  66.  
  67. Cheers
  68. Tanmoy
  69. --
  70. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  71. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  72. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  73. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  74. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  75. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  76.